package com.fudan.es.aggs.request.handler.dimension;

import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.springframework.stereotype.Component;

import com.fudan.es.Aggs;
import com.fudan.es.entity.DimensionPack;
import com.fudan.es.entity.FieldMeta;

public class DateHandler extends DimensionHandler{
	@Override
	public AggregationBuilder handle(DimensionPack dimension) {
		FieldMeta field = dimension.getField();
		if(field == null) {
			throw new RuntimeException(NO_FIELD);
		}
		if(!field.getAggregatable()) {
			throw new RuntimeException(FIELD_NOT_AGGREGATABLE);
		}
			return Aggs.date(dimension);
	}


}
